Color OLED module library  v0.5
Library for the WaveShare 0.96-inch color OLED (SSD1331) module
ssd1331_spiWrite.c
1 /*
2  * @file ssd1331_spiWrite.c
3  *
4  * @author Matthew Matz
5  *
6  * @version 0.9
7  *
8  * @copyright Copyright (C) Parallax, Inc. 2019. See end of file for
9  * terms of use (MIT License).
10  *
11  * @brief 0.96-inch RGB OLED display bitmap driver, see oledc_h. for documentation.
12  *
13  * @detail Please submit bug reports, suggestions, and improvements to
14  * this code to editor@parallax.com.
15  */
16 
17 
18 #include "ssd1331.h"
19 
20 // ------------------- low level pin interface --------------------
21 static char _writeLock;
22 
23 
24 __attribute__((fcache)) // allows function to run directly from cog ram, 10x+ speed increase
25 void ssd1331_writeByte(int mask_cs, int mask_sdi, int mask_clk, int mask_dc, char c, char dc) {
26 
27  // Conditionally set _rs (Source: https://graphics.stanford.edu/~seander/bithacks.html)
28  unsigned int mask = (-(dc) ^ OUTA) & mask_dc;
29  OUTA ^= mask;
30 
31  OUTA &= ~mask_cs;
32  OUTA &= ~mask_clk; // Pin output state to low
33  DIRA |= mask_clk; // Pin direction to output
34 
35  for (int i = 7; i >= 0 ; i--) {
36  if ((c >> i) & 1) OUTA |= mask_sdi;
37  else OUTA &= (~mask_sdi);
38  OUTA ^= mask_clk;
39  OUTA ^= mask_clk;
40  }
41  OUTA |= mask_cs;
42 }
43 
44 char ssd1331_writeLock() {
45  return _writeLock;
46 }
47 
48 void ssd1331_writeLockSet(char devId) {
49  while(_writeLock);
50  _writeLock = devId;
51 }
52 
53 void ssd1331_writeLockClear(char devId) {
54  if (_writeLock == devId) {
55  _writeLock = 0;
56  }
57 }
58 
59 
60